<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="危废名称" prop="wasteName">
                <el-input v-model="queryParams.wasteName" placeholder="请输入危废名称" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="批次号码" prop="batchNumber">
                <el-input v-model="queryParams.batchNumber" placeholder="请输入批次号码" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="危废状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择危废状态">
                    <el-option v-for="dict in wasteFlowStatusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
                </el-select>
            </el-form-item>
            <el-form-item label="危废仓库" prop="warehouseId">
                <el-select v-model="queryParams.warehouseId" placeholder="请选择仓库">
                    <el-option v-for="item in warehouseList" :label="item.warehouseName" :key="item.warehouseId" :value="item.warehouseId" />
                </el-select>
            </el-form-item>
            <el-form-item label="申报日期">
                <el-date-picker v-model="daterangeDeclareDate" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="申报人" label-width="100px">
                <el-input v-model="queryParams.declareOperator" placeholder="请输入申报人" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="收运日期">
                <el-date-picker v-model="daterangeCollectDate" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="收运者" label-width="100px" prop="collector">
                <el-input v-model="queryParams.collector" placeholder="请输入收运者" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="入库日期">
                <el-date-picker v-model="daterangeEntryDate" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item label-width="100px" label="入库操作者" prop="entryOperator">
                <el-input v-model="queryParams.entryOperator" placeholder="请输入操作者姓名" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="出库日期">
                <el-date-picker v-model="daterangeOutDate" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label-width="100px" label="出库操作者" prop="outOperator">
                <el-input v-model="queryParams.outOperator" placeholder="请输入操作者姓名" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="处置方式" prop="handleMethod">
                <el-select v-model="queryParams.handleMethod" placeholder="请选择处置方式">
                    <el-option v-for="item in wasteHandlerMethodList" :label="item.dictLabel" :key="item.dictValue" :value="item.dictValue" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport" v-hasPermi="['business:wasteInventory:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="wasteInventoryList" @selection-change="handleSelectionChange">
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <el-table-column label="主键id" align="center" prop="wasteInventoryId" v-if="false" />
            <el-table-column label="危废收运ID" align="center" prop="wasteCollectId" v-if="false" />
            <el-table-column label="批次号码" align="center" prop="batchNumber" width="180" />
            <el-table-column label="状态" align="center" prop="status" width="100" :formatter="wasteFlowStatusFormat" />
            <el-table-column type="expand">
                <template slot-scope="props">
                    <keep-alive>
                        <waste-info-card :row="props.row" />
                    </keep-alive>
                </template>
            </el-table-column>
            <el-table-column label="危废名称" align="left" prop="wasteName" width="180" />
            <el-table-column label="预估重量" align="center" prop="wasteDiscreetWeight" width="120" />
            <el-table-column label="申报人" align="center" prop="declareOperator" width="100" />
            <el-table-column label="申报日期" align="center" prop="declareDate" width="150" />
            <el-table-column label="收运人" align="center" prop="collectorOperator" width="100" />
            <el-table-column label="收运日期" align="center" prop="collectDate" width="150" />
            <el-table-column label="仓库名称" align="center" prop="warehouseName" width="120" />
            <el-table-column label="危废实重" align="center" prop="wasteWeight" width="100" />
            <el-table-column label="入库日期" align="center" prop="entryDate" width="150" />
            <el-table-column label="入库操作者" align="center" prop="entryOperator" width="100" />
            <el-table-column label="原仓库" align="center" prop="fromWarehouseName" width="120" />
            <el-table-column label="转入仓库" align="center" prop="toWarehouseName" width="120" />
            <el-table-column label="转库日期" align="center" prop="transferDate" width="150" />
            <el-table-column label="转库操作者" align="center" prop="transferOperator" width="100" />
            <el-table-column label="出库日期" align="center" prop="outDate" width="150" />
            <el-table-column label="出库操作者" align="center" prop="outOperator" width="100" />
            <el-table-column label="处置方式" align="center" prop="handleMethod" :formatter="handleMethodFormat" width="120" />
            <el-table-column label="处置公司" align="center" prop="handleCompanyKey" :formatter="handleCompanyKeyFormat" width="150" />
            <el-table-column label="焚化方式" align="center" prop="incinerateMethod" :formatter="incinerateMethodFormat" width="120" />
            <el-table-column label="焚化日期" align="center" prop="incinerateDate" width="150" />
            <el-table-column label="焚化操作者" align="center" prop="incinerateOperator" width="100" />
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import { wasteFlowInfoList, exportWasteFlowInfo } from "@/api/business/report";
import { listWarehouseForSelect } from "@/api/system/warehouse";
import WasteInfoCard from "@/views/business/wasteInfoCard";

import { mapActions, mapGetters } from "vuex";

export default {
    name: "WasteFlowInfo",
    components: {
        WasteInfoCard
    },
    data() {
        return {
            //按钮loading
            buttonLoading: false,
            // 遮罩层
            loading: true,
            // 导出遮罩层
            exportLoading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 危废库存信息表格数据
            wasteInventoryList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                wasteId: undefined,
                warehouseId: undefined,
                wasteName: undefined,
                batchNumber: undefined,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
            },
            // 仓库列表
            warehouseList: [],
            // 处置方式字典
            wasteHandlerMethodList: [],
            // 处置公司字典
            wasteHandleCompanyList: [],
            // 焚化方式列表
            incinerateMethodList: [],
            // 焚化日期范围
            daterangeIncinerateDate: [],
            // 入库日期范围
            daterangeEntryDate: [],
            // 出库日期范围
            daterangeOutDate: [],
            // 申报日期日期范围
            daterangeDeclareDate: [],
            // 收运日期日期范围
            daterangeCollectDate: [],
        };
    },
    created() {
        this.getList();
        this.initDictData();
        this.getHandleMethodList();
        this.getHandleCompanyList();
        this.getIncinerateMethodList();
        this.getWarehouseList();
    },
    computed: {
        ...mapGetters(["wasteFlowStatusOptions"]),
    },
    methods: {
        ...mapActions({
            initDictData: "initDataForWasteInfoCard",
        }),
        /** 查询危废库存信息列表 */
        getList() {
            this.loading = true;
            this.queryParams.params = {};
            if (null != this.daterangeDeclareDate && "" != this.daterangeDeclareDate) {
                this.queryParams.params["beginDeclareDate"] = this.daterangeDeclareDate[0];
                this.queryParams.params["endDeclareDate"] = this.daterangeDeclareDate[1];
            }
            if (null != this.daterangeCollectDate && "" != this.daterangeCollectDate) {
                this.queryParams.params["beginCollectDate"] =
                    this.daterangeCollectDate[0];
                this.queryParams.params["endCollectDate"] =
                    this.daterangeCollectDate[1];
            }
            if (null != this.daterangeEntryDate && '' != this.daterangeEntryDate) {
                this.queryParams.params["beginEntryDate"] = this.daterangeEntryDate[0];
                this.queryParams.params["endEntryDate"] = this.daterangeEntryDate[1];
            }
            if (null != this.daterangeOutDate && '' != this.daterangeOutDate) {
                this.queryParams.params["beginOutDate"] = this.daterangeOutDate[0];
                this.queryParams.params["endOutDate"] = this.daterangeOutDate[1];
            }
            if (null != this.daterangeIncinerateDate && '' != this.daterangeIncinerateDate) {
                this.queryParams.params["beginIncinerateDate"] = this.daterangeIncinerateDate[0];
                this.queryParams.params["endIncinerateDate"] = this.daterangeIncinerateDate[1];
            }
            wasteFlowInfoList(this.queryParams).then(response => {
                this.wasteInventoryList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 获取仓库列表
        getWarehouseList() {
            listWarehouseForSelect().then(response => {
                this.warehouseList = response.data;;
            });
        },
        /** 获取处置方式 */
        getHandleMethodList() {
            this.getDicts("waste_handler_method").then((response) => {
                this.wasteHandlerMethodList = response.data;
            });
        },
        /** 获取处置公司 */
        getHandleCompanyList() {
            this.getDicts("waste_handle_company").then((response) => {
                this.wasteHandleCompanyList = response.data;
            });
        },
        /** 获取焚化方式 */
        getIncinerateMethodList() {
            this.getDicts("incinerate_method").then((response) => {
                this.incinerateMethodList = response.data;
            });
        },
        // 处置方式字典翻译
        handleMethodFormat(row, column) {
            return this.selectDictLabel(this.wasteHandlerMethodList, row.handleMethod);
        },
        // 处置公司名称字典翻译
        handleCompanyKeyFormat(row, column) {
            return this.selectDictLabel(this.wasteHandleCompanyList, row.handleCompanyKey);
        },
        // 焚化方式字典翻译
        incinerateMethodFormat(row, column) {
            return this.selectDictLabel(this.incinerateMethodList, row.incinerateMethod);
        },
        // 危废状态字典翻译
        wasteFlowStatusFormat(row, column) {
            return this.selectDictLabel(
                this.wasteFlowStatusOptions,
                row.status
            );
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.daterangeIncinerateDate = [];
            this.daterangeEntryDate = [];
            this.daterangeOutDate = [];
            this.daterangeDeclareDate = [];
            this.daterangeCollectDate = [];
            this.daterangeIncinerateDate = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.wasteInventoryId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.exportLoading = true;
                return exportWasteFlowInfo(queryParams);
            }).then(response => {
                this.download(response.msg);
                this.exportLoading = false;
            }).catch(() => { });
        }
    }
};
</script>
<style>
.demo-table-expand {
    font-size: 0;
    padding: 0px 0px 0px 150px;
    max-width: 1200px;
}
.demo-table-expand label {
    width: 90px;
    color: #99a9bf;
}
.demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
}
</style>